﻿using ServiceContracts.DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Services.Helpers
{
    public class validationHelper
    {
        //模型验证
        internal static void ModelValidation(object obj)
        {
            ValidationContext validationContext = new ValidationContext(obj);
            List<ValidationResult> validationresults = new List<ValidationResult>();
            bool isValid = Validator.TryValidateObject(obj, validationContext, validationresults, true);
            if (!isValid)
            {
                throw new ArgumentException(validationresults.FirstOrDefault()?.ErrorMessage);
            }
        }
    }
}
